package action;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import pageModel.EasyuiTreeNode;
import pageModel.GoodTypes;
import pageModel.Json;
import service.GoodTypesServiceI;

import com.opensymphony.xwork2.ModelDriven;

@Namespace("/")
@Action(value="goodTypesAction",results = { @Result(name = "goodTypesAdd", location = "/admin/splxAdd.jsp"), @Result(name = "goodTypesEdit", location = "/admin/splxEdit.jsp")})
public class GoodTypesAction extends BaseAction implements ModelDriven<GoodTypes>{
private GoodTypesServiceI goodTypesService;
GoodTypes goodtypes=new GoodTypes();
public GoodTypesServiceI getGoodTypesService() {
	return goodTypesService;
}
@Autowired
public void setGoodTypesService(GoodTypesServiceI goodTypesService) {
	this.goodTypesService = goodTypesService;
}
public GoodTypes getModel(){
	return goodtypes;
}
public String goodTypesAdd() {
	return "goodTypesAdd";
}

public String goodTypesEdit() {
	return "goodTypesEdit";
}
public void tree()  {
	super.writeJson(goodTypesService.allTreeNode(goodtypes.getId()));
}
public void treegrid() {
	super.writeJson(goodTypesService.treegrid(goodtypes.getId()));
}
public void add(){
	Json j=new Json();
	try{
		goodTypesService.save(goodtypes);
		j.setSuccess(true);
		j.setMsg("添加成功!");
	}catch(Exception e){
		j.setMsg("添加失败,该商品类型在数据库中已存在!");
	}
	super.writeJson(j);
}
public void editor(){
	Json j=new Json();
	try{
		goodTypesService.edit(goodtypes);
		j.setSuccess(true);
		j.setMsg("编辑成功!");
	}catch(Exception e){
		j.setMsg("编辑失败!");
	}
	super.writeJson(j);
}
public void del(){
	Json j=new Json();
	try{
		goodTypesService.remove(goodtypes.getId());
		j.setSuccess(true);
		j.setMsg("删除成功!");
	}catch(Exception e){
		j.setMsg("删除失败!");
	}
	super.writeJson(j);
}
}
